package com.itcast.demoone.kotlin

fun main() {
    // 1. 主构造函数实例对象
    val vehicle = Vehicle("轿车")
    vehicle.intro()

    // 2. 次构造函数实例对象
    val vehicle2 = Vehicle("自行车", 3)
    vehicle2.intro()

}


class Vehicle(val type: String){
    var wheels: Int = 0
    init {
        wheels = when(type) {
            "轿车" -> 4
            "自行车" -> 2
            "飞机" -> 6
            "大卡车" -> 8
            else -> 0
        }
    }

    constructor(type: String, wheels: Int) : this(type) {
        this.wheels = wheels
    }

    fun intro() {
        println("这是一辆${type}，有${wheels}个轮子")
    }

}